package br.iars.model.recommendation.util;

import java.util.List;
import java.util.NoSuchElementException;

import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator;

public class LongPrimitiveListIterator implements LongPrimitiveIterator {

	private List<Long> list;
	private int position;
	private final int max;

	public LongPrimitiveListIterator(List<Long> list) {
		super();
		this.list = list;
		this.position = 0;
		this.max = this.list.size();
	}

	public void skip(int n) {
		if (n > 0) {
			position += n;
		}
	}

	public boolean hasNext() {
		return position < max;
	}

	public Long next() {
		return nextLong();
	}

	public void remove() {
		throw new UnsupportedOperationException();
	}

	public long nextLong() {
		if (position >= max) {
			throw new NoSuchElementException();
		}
		return list.get(position++);
	}

	public long peek() {
		if (position >= max) {
			throw new NoSuchElementException();
		}
		return list.get(position);
	}

	public String toString() {
		return "LongPrimitiveListIterator [list=" + list + ", position="
				+ position + ", max=" + max + "]";
	}

}
